﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Net;


namespace CodeDemon
{
	public class GlobalApplication : System.Web.HttpApplication
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapRoute(
				"Default",                                              // Route name
				"{controller}/{action}/{id}",                           // URL with parameters
				new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
			);

		}

		protected void Application_Start(object sender, EventArgs e)
		{
			RegisterRoutes(RouteTable.Routes);
		}

		//protected void Application_Error(object sender, EventArgs e)
		//{
		//    Exception objErr = Server.GetLastError().GetBaseException();
		//    string err = "<h1>System Error</h1><p>Error Caught in Application_Error event</p>" +
		//            "<p>Error in: " + Request.Url.ToString() +
		//            "</p><p>Error Message:" + objErr.Message.ToString();
		//    // add ERROR
		//    String strHostName = Dns.GetHostName();
		//    IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
		//    IPAddress[] addr = ipEntry.AddressList;
		//    String foo = String.Format(
		//            "Browser:{0}ErrorDescription:{1}ErrorSource:{2}StackTrace:{5}ErrorTime:{3}ServerName:{4}",
		//            Request.UserAgent + Environment.NewLine,
		//            objErr.Message + Environment.NewLine,
		//            objErr.Source + Environment.NewLine,
		//            DateTime.Now + Environment.NewLine,
		//            addr[0] + Environment.NewLine,
					
		//            Environment.NewLine + objErr.StackTrace.ToString() + Environment.NewLine);

			
		//    Response.Write(err);
		//    Response.Write("<pre>" +foo + "</pre>");
		//    Server.ClearError();
		//    Response.Write("<h2>Form Data</h2>");
		//    Response.Write("<table>");
		//    for (int i = 0; i < Request.Form.Count; i++)  
		//    {
		//        Response.Write("<tr><td>" + Request.Form.GetKey(i) + "</td><td>==</td><td>" + Request.Form.Get(i) + "</td></tr>");
		//    }
		//    Response.Write("</table>");
		//    foo += Environment.NewLine + Environment.NewLine;
		//    for (int i = 0; i < Request.Form.Count; i++)
		//    {
		//        foo += Request.Form.GetKey(i) + "=" + Request.Form.Get(i) + Environment.NewLine; 
		//    }

		//    Response.Write("<h2><a href=\"http://THIS_SERVER/bugzilla/enter_bug.cgi?assigned_to=cory.trese%40standardregister.com&attachurl=&blocked=&bug_file_loc=" + Request.Url.ToString() + "&bug_severity=normal&bug_status=NEW&comment=" + HttpUtility.UrlEncode(objErr.Message) + "&component=Code%20Review%20System&contenttypeentry=&contenttypemethod=autodetect&contenttypeselection=text%2Fplain&data=&dependson=&description=&flag_type-1=X&flag_type-10=X&flag_type-11=X&flag_type-2=X&flag_type-3=X&flag_type-4=X&flag_type-5=X&flag_type-6=X&flag_type-8=X&flag_type-9=X&form_name=enter_bug&keywords=&maketemplate=Remember%20values%20as%20bookmarkable%20template&op_sys=Windows&priority=P4&product=Development%20Tools&qa_contact=&rep_platform=---&short_desc=" + objErr.Message.ToString() + "&target_milestone=---&version=other\">Report This Error</a></h2>");
		//    //http://THIS_SERVER/bugzilla/enter_bug.cgi?assigned_to=&attachurl=&blocked=&bug_file_loc=http%3A%2F%2F&bug_severity=normal&bug_status=NEW&comment=asdf&contenttypeentry=&contenttypemethod=autodetect&contenttypeselection=text%2Fplain&data=&dependson=&description=&flag_type-1=X&flag_type-10=X&flag_type-11=X&flag_type-2=X&flag_type-3=X&flag_type-4=X&flag_type-5=X&flag_type-6=X&flag_type-7=X&flag_type-8=X&flag_type-9=X&form_name=enter_bug&keywords=&maketemplate=Remember%20values%20as%20bookmarkable%20template&op_sys=Windows&priority=P4&product=Development%20Tools&qa_contact=&rep_platform=---&short_desc=asdf&target_milestone=---&version=other
		//    Response.Write("<h2><a href='/CodeDemon/Home'>Give Up</a></h2>");
		//}
	}
}